/**
 * 数据埋点初始化
 */

import { initTrack } from '@alife/yunxiao-common';
import firstSession from './firstSession';
import { isAliyunDomain } from 'utils/tenant';

export default function () {
  const { user, organization, env } = window.FORCE;

  // 非正式环境、集团环境不打点
  if (env !== 'PRODUCTION' || !isAliyunDomain) {
    if (isAliyunDomain) {
      // 方便线下环境测试
      firstSession();
    }
    return false;
  }

  // 注册用户、mp_lib
  const userId = user && user.id;
  if (userId) {
    firstSession();
  }

  initTrack({
    userId,
    organizationId: organization.organization_id,
    appName: 'codeup',
    autoTrack: true,
  });
}
